package com.qlslylq.ad.sdk.enums;

import com.qlslylq.ad.sdk.util.Log;

/**
 * 广告类型(穿山甲横幅物料尺寸模板)<br/>
 */
public enum AdSize {

    SIZE_DEFAULT("SIZE_600_90", "c_b_30045", 300, 45),
    SIZE_600_300("SIZE_600_300", "c_b_300150", 300, 150),
    SIZE_600_400("SIZE_600_400", "c_b_300200", 300, 200),
    SIZE_600_500("SIZE_600_500", "c_b_300250", 300, 250),
    SIZE_600_260("SIZE_600_260", "c_b_300130", 300, 130),
    SIZE_600_90("SIZE_600_90", "c_b_30045", 300, 45),
    SIZE_600_150("SIZE_600_150", "c_b_30075", 300, 75),
    SIZE_640_100("SIZE_640_100", "c_b_32050", 320, 50),
    SIZE_640_180("SIZE_640_180", "c_b_32090", 320, 90),//MB
    SIZE_690_388("SIZE_690_388", "c_b_345194", 345, 194);

    private String id;

    private String name;

    //物料宽度
    private int width;

    //物料高度
    private int height;

    AdSize(String id, String name, int width, int height) {
        this.id = id;
        this.name = name;
        this.width = width;
        this.height = height;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getWidth() {
        return width;
    }

    public void setWidth(int width) {
        this.width = width;
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    public static AdSize getEnumByName(String name) {
        for (AdSize item : AdSize.values()) {
            if (item.getName().equals(name)) {
                return item;
            }
        }
        return null;
    }

    /**
     * 数据加工<br/>
     * 优先使用管理后台上申请的尺寸<br/>
     */
    public static AdSize process(AdSize adSize, String measureSign) {
        AdSize resultSize = AdSize.getEnumByName(measureSign);
        if (resultSize == null) {
            resultSize = adSize == null ? AdSize.SIZE_DEFAULT : adSize;
            if (adSize == null) {
                Log.dp(String.format("当前广加载中[尺寸]：使用默认尺寸：%s", AdSize.SIZE_DEFAULT.getName()));
            } else {
                Log.dp(String.format("当前广告加载中[尺寸]：使用app端尺寸：%s", adSize.getName()));
            }
        } else {
            Log.dp(String.format("当前广告加载中[尺寸]：使用后端尺寸：%s", resultSize.getName()));
        }
        return resultSize;
    }

    /**
     * 获取充满父容器宽度后的高度(按物料内容的原始比例，缩放物料内容至容器宽度)<br/>
     */
    public int getRealHeight(int adContainerWidth) {
        float ratio = (float) width / height;
        return (int) Math.ceil(adContainerWidth / ratio);
    }

}
